package cc.customer.authorization.interceptor;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cc.customer.authorization.resolvers.CurrentUserMethodArgumentResolver;

@Configuration	
public class AuthWebAppConfigurer implements WebMvcConfigurer {
	
	@Autowired
	AuthorizationInterceptor authorizationInterceptor;
	
	@Autowired
	CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver;
	
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration addInterceptor = registry.addInterceptor(authorizationInterceptor);
		addInterceptor.excludePathPatterns("/app/login");
        //拦截配置
        addInterceptor.addPathPatterns("/**");
    }
	
	@Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
		argumentResolvers.add(currentUserMethodArgumentResolver);
    }
}
